package com.im.project.controller;

import com.im.common.annotation.RedisLimit;
import com.im.common.result.JsonResult;
import com.im.project.entity.dto.MessageTopDto;
import com.im.project.entity.dto.SendMessageDto;
import com.im.project.service.ChatMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 会话消息 控制层
 *
 * @author yunZhouJiaDi
 */
@RestController
@RequestMapping("/message")
@Api(tags = "ChatMessageController", description = "会话消息相关接口")
public class ChatMessageController {

    @Resource
    private ChatMessageService chatMessageService;

    @PostMapping("/sendPrivateMessage")
    @ApiOperation("发送私聊消息")
    @RedisLimit(key = "sendPrivateMessage", period = 10, count = 6)
    public JsonResult sendPrivateMessage(@Validated @RequestBody SendMessageDto sendMessageDto) {
        return JsonResult.success(chatMessageService.sendPrivateMessage(sendMessageDto));
    }

    @PostMapping("/sendClusterMessage")
    @ApiOperation("发送群聊消息")
    @RedisLimit(key = "sendClusterMessage", period = 10, count = 6)
    public JsonResult sendClusterMessage(@Validated @RequestBody SendMessageDto sendMessageDto) {
        return JsonResult.success(chatMessageService.sendClusterMessage(sendMessageDto));
    }

    @PutMapping("/{contactId}")
    @ApiOperation("私聊消息已读")
    public JsonResult updateReadMsgState(@PathVariable String contactId) {
        return JsonResult.success(chatMessageService.updateReadMsgState(contactId));
    }

    @PostMapping("/top")
    @ApiOperation("置顶消息")
    public JsonResult setMessageTop(@Validated @RequestBody MessageTopDto messageTopDto) {
        return JsonResult.success(chatMessageService.setMessageTop(messageTopDto));
    }

}
